<template>
  <PublicPage :pageName="activeIndex === 0 ? '我的订单' : '卖出订单'">
    <!-- 自定义头部 -->
    <!-- <view class="tabsBox" slot="headNav">
      <view class="tabs" v-for="(item,index) in categories" :key="index" :class="{'activeTbs': activeIndex === index}" @click="changeIndex(index)">{{item}}</view>
    </view> -->
    <MyBuyOrderList ref="list1" :class="{'displayNone': activeIndex === 1}"/>
    <SellerOrderList ref="list2" :class="{'displayNone': activeIndex === 0}"/>
  </PublicPage>
</template>

<script>
import PublicPage from "@/components/publicPage/index.vue";
import MyBuyOrderList from './components/myBuyOrderList.vue'
import SellerOrderList from './components/sellerOrderList.vue'

import mini from '@/api/mini.js'
export default {
  name: 'Order',
  components: {
    PublicPage,
    MyBuyOrderList,
    SellerOrderList,
  },
  // computed: {
  //   globalData () {
  //     return this.$store.state.globalData
  //   }
  // },
  data () {
    return {
      // 当前选中下标
      activeIndex: 0,
      // 子级类型
      childType: 0,

      // categories: ["我买入的","我卖出的"],
    }
  },
  onLoad(options){
    this.shareOptions(options) // 分享参数处理
    
    this.activeIndex = Number(options.type) || 0
    this.childType = Number(options.childType) || 0
  },
  onShow(){

    // if(this.$store.state.shareRouteData.activeIndex){
    //   this.activeIndex = this.$store.state.shareRouteData.activeIndex
    //   this.$store.commit('SHARE_ROUTE_DATA', {})
    // }
    this.loadList()

    // 获取红点规则
    if(this.isLogin){
      mini.getMyPageInfo().then(res=>{
        this.$store.commit('SET_MY_PAGEINFO',res.data)
      })
    }
  },
  methods: {
    // 切换订单角色
    // changeIndex (index) {
    //   if(index === this.activeIndex) return
    //   this.activeIndex = index
    //   this.loadList()
    // },
    loadList(){
      if(this.isLogin){
        if(this.activeIndex == 0){
          this.$refs.list1.showBar = true
          this.$refs.list2.showBar = false

          if(this.childType){this.$refs.list1.getParams.type = this.childType;this.childType = 0}
          if(this.$refs.list1.getParams.type == 4){ 
            this.$refs.list1.interruptAfter() // 售后刷新
          }else{
            this.$refs.list1.interruptOrder() // 订单刷新
          }
        }else{
          this.$refs.list1.showBar = false
          this.$refs.list2.showBar = true

          if(this.childType){this.$refs.list2.tabsIndex = this.childType;this.childType = 0}
          if(this.$refs.list2.tabsIndex == 3){
            this.$refs.list2.interruptAfter() // 售后刷新
          }else{
            this.$refs.list2.interruptOrder() // 订单刷新
          }
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.displayNone{
  display: none !important;
}
// .tabsBox {
//   margin-left: 18rpx;
//   width: 352rpx;
//   line-height: 64rpx;
//   font-size: 28rpx;
//   border-radius: 32rpx;
//   color: #969799;
//   background-color: #F5F5F5;
//   display: flex;
//   align-items: center;
//   .tabs{
//     width: 50%;
//     text-align: center;
//     border-radius: 32rpx;
//   }
//   .tabs.activeTbs{
//     background: #E44435;
//     color: #FFFFFF;
//   }
// }
</style>